package io.renren.dao;

import io.renren.common.dao.BaseDao;
import io.renren.dto.AuxiliaryMateriDTO;
import io.renren.dto.AuxiliaryMaterialsmxDTO;
import io.renren.entity.AuxiliaryMaterialsmxEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 辅材采购明细表
 *
 * @author 罗胜平 781757616@qq.com
 * @since 1.0.0 2019-11-22
 */
@Mapper
public interface AuxiliaryMaterialsmxDao extends BaseDao<AuxiliaryMaterialsmxEntity> {


    @Select("DELETE from canteens_auxiliary_materialsmx where auxiliary_materialsmx_id = " +
            "'${order}' ")
    void deleteOrder( Long order);

    //查询一个订单下所有供应商
    @Select("SELECT * FROM canteens_auxiliary_materialsmx mx,canteens_supplier s WHERE mx.auxiliary_materials_id ="+" '${id}' " +
            "AND mx.supplier_id=s.supplier_id GROUP BY mx.supplier_id")
    List<AuxiliaryMaterialsmxDTO> seletGys(Long id);
    //查询供应商
    @Select("SELECT * FROM canteens_auxiliary_materialsmx mx WHERE mx.auxiliary_materials_id ="+" '${id}' ")
    List<AuxiliaryMaterialsmxDTO> seletMx(Long id);
    //查询供应商下的材料信息

    @Select("SELECT mx.*, f.food_name,f.unit ,A.create_date FROM canteens_auxiliary_materialsmx mx LEFT JOIN canteens_food f ON mx.food_id = f.food_id " +
            " LEFT JOIN canteens_auxiliary_materi A on a.auxiliary_materials_id = mx.auxiliary_materials_id" +
            " WHERE mx.auxiliary_materials_id = '${id}' AND mx.supplier_id = '${ids}'")
    List<AuxiliaryMaterialsmxDTO> seletGysFood(long id,long ids);
    //查询供应商下的材料信息

    @Select("SELECT mx.sub_status,mx.auxiliary_materialsmx_id FROM canteens_auxiliary_materialsmx mx WHERE mx.auxiliary_materials_id = '${id}' " +
            "AND mx.supplier_id = '${ids}' ")
    List<AuxiliaryMaterialsmxDTO> seletGysFood1(long id,long ids);
    //查询已报价的供应商

    @Select("SELECT m.create_date as create_date ,mx.*,s.* FROM canteens_auxiliary_materialsmx mx,canteens_supplier s,canteens_auxiliary_materi m WHERE mx.auxiliary_materials_id ="+" '${id}' " +
            "and mx.auxiliary_materials_id = m.auxiliary_materials_id  AND mx.supplier_id=s.supplier_id and  mx.sub_status = 1  GROUP BY mx.supplier_id ")
    List<AuxiliaryMaterialsmxDTO> gys1(Long id);

    @Select("UPDATE canteens_auxiliary_materialsmx set sub_status = '${subStutas}' where auxiliary_materialsmx_id = '${id} '")
    void updateOrder1(long id,long subStutas);

    @Select("SELECT * FROM canteens_auxiliary_materialsmx where auxiliary_materialsmx_id = " +"'${id}' ")
    AuxiliaryMaterialsmxDTO gysMx(long id);

    @Select("UPDATE canteens_auxiliary_materialsmx set purchase_num = '${purchaseNum}' where auxiliary_materialsmx_id =${orderId}  and food_id = ${foodId} ")
    void updateOrder2(long orderId,long foodId,float purchaseNum);
    @Select("DELETE from canteens_auxiliary_materialsmx where auxiliary_materialsmx_id =${orderId}  and food_id = ${foodId} ")
    void delectOrder1(long orderId,long foodId);
}